//
//  NavigationBar.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/8/13.
//
//

#include "NavigationBar.h"


bool NavigationBar::init(){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    double titleHeight = winSize.height*0.05f;
    double navigationBarHeight = titleHeight*1.5f;
    titleLabel = CCLabelBMFont::create("title", "Info.fnt");
    titleLabel->setAnchorPoint(ccp(0.5,0.5));
    titleLabel->setScale(titleHeight / titleLabel->getContentSize().height);
    titleLabel->setPosition(ccp(winSize.width/2,winSize.height - navigationBarHeight/2));
    this->addChild(titleLabel);
    
    
    backButton = MyPageButton::create("back_button.png", 0, winSize.height-navigationBarHeight, navigationBarHeight*1.5f, navigationBarHeight);
    CCCallFuncO* callback = CCCallFuncO::create(this, callfuncO_selector(NavigationBar::onTapBackButton), this);
    backButton->addCallback(callback);
    this->addChild(backButton);
    setTouchEnabled(true);
    return true;
}


void NavigationBar::setTitle(const char *newTitle){
    titleLabel->setString(newTitle);
}

void NavigationBar::onTapBackButton(cocos2d::CCObject *sender){
    CCLOG("back");
}

void NavigationBar::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    backButton->handleTouchesBegan(touches, pEvent);
}
void NavigationBar::ccTouchesMoved(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    backButton->handleTouchesMoved(touches, pEvent);
}
void NavigationBar::ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    backButton->handleTouchesEnded(touches, pEvent);
}